import React from 'react';
import { Button } from 'antd';
import type { ButtonProps } from 'antd';
import { useModel } from '@umijs/max';

interface AuthButtonProps extends ButtonProps {
  permissionPath: string;  // 按钮的权限路径
}

const AuthButton: React.FC<AuthButtonProps> = ({ permissionPath, children, ...props }) => {
  const { initialState } = useModel('@@initialState');
  const { buttons = [] } = initialState || {};

  // 检查权限
  if (!buttons.includes(permissionPath)) {
    return null;
  }

  return <Button {...props}>{children}</Button>;
};

export default AuthButton;
